<template>
  <div id="rolePreview">
    <div style="text-align: right; margin-bottom: 10px;">
      <el-button type="primary" round size="medium" @click="cancelSave">返回</el-button>
    </div>
    <el-table :data="tableData" :span-method="arraySpanMethod" border style="width: 100%">
      <el-table-column prop="roleName" label="角色名称" width="180">
      </el-table-column>
      <el-table-column prop="name" label="权限模块" width="180">
      </el-table-column>
      <el-table-column prop="childTest" label="授予权限明细">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapState } from 'vuex';
export default {
  name: "rolePreview",
  data() {
    return {
      tableData: [],
    };
  },
  computed: {
    ...mapState({
      tagCurrent: state => state.tag.tagCurrent,
    })
  },
  methods: {
    arraySpanMethod({ column, rowIndex }) {
      if (column.property === 'roleName') {
        if (rowIndex === 0) {
          return {
            rowspan: this.tableData.length,
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
    },
    cancelSave() {
      this.$store.commit('DEL_TAG', this.tagCurrent);
      this.$router.replace({ name: 'roleManagement' });
    },
    getJurisdiction() {
      let Params = {
        roleid: this.$route.query.roleid
      };
      this.$api.systemManagement.GetRoleAuthorityTwoLevelTree(Params).then(res => {
        if (res.data.status != 200) {
          this.tableData = [];
          return;
        }
        let rowData = res.data.data;
        let tableData = [];
        rowData.map(item => {
          if (item.level == 1) {
            item.childs = [];
            tableData.push(item);
          }
        });
        tableData.map(item => {
          rowData.map(items => {
            if (item.id == items.parentid) {
              item.childs.push(items);
            }
          });
        });
        tableData.map(item => {
          item.childTest = '';
          item.roleName = this.$route.query.roleName;
          item.childs.map(items => {
            item.childTest += items.name + ' ';
          });
        });
        this.tableData = tableData;
      });
    }
  },
  created() {

  },
  activated() {
    this.getJurisdiction();
  }
};
</script>

<style lang="less">
</style>
